package com.platform.comm.common.batch.listener;

import com.platform.vo.BatchResult;
import com.platform.vo.ImportDto;
import com.platform.comm.common.batch.ComBatchContext;
import org.springframework.batch.core.annotation.AfterProcess;
import org.springframework.batch.core.annotation.BeforeProcess;
import org.springframework.batch.core.annotation.OnProcessError;

/**
 * @author Administrator
 */
public class ImportDataProcessCountListener {

    private BatchResult batchResult;

    public ImportDataProcessCountListener(ComBatchContext context) {
        this.batchResult = context.getBatchResult();
    }


    @BeforeProcess
    public void beforeProcess(ImportDto item) {
        this.batchResult.increaseProcessCount();
    }

    @AfterProcess
    public void afterProcess(ImportDto item, ImportDto result) {
        if (!result.isFlag()) {
            this.batchResult.increaseErrorCount();
        }

    }

    @OnProcessError
    public void onProcessError(ImportDto item, Exception e) {
        this.batchResult.increaseErrorCount();
    }
}
